//
// SecCertificate Unit Tests
//
// Authors:
//	Sebastien Pouliot  <sebastien@xamarin.com>
//
// Copyright 2012 Xamarin Inc.
//

using System.Diagnostics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

using Security;

namespace MonoTouchFixtures.Security {

	[TestFixture]
	// we want the test to be available if we use the linker
	[Preserve (AllMembers = true)]
	public class CertificateTest {

		// Subject: CN=mail.google.com
		static public byte [] mail_google_com = {
			0x30, 0x82, 0x04, 0x6a, 0x30, 0x82, 0x03, 0x52, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x72,
			0xcd, 0x64, 0xe0, 0x1f, 0xb6, 0x09, 0x45, 0x10, 0x85, 0xa3, 0x90, 0x91, 0xb5, 0x31, 0x28, 0x30,
			0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b,
			0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x1e, 0x30,
			0x1c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x15, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54,
			0x72, 0x75, 0x73, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x31, 0x0c, 0x30,
			0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x57, 0x52, 0x32, 0x30, 0x1e, 0x17, 0x0d, 0x32,
			0x35, 0x30, 0x38, 0x32, 0x35, 0x30, 0x38, 0x34, 0x31, 0x35, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x35,
			0x31, 0x31, 0x31, 0x37, 0x30, 0x38, 0x34, 0x31, 0x34, 0x39, 0x5a, 0x30, 0x1a, 0x31, 0x18, 0x30,
			0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x67, 0x6f, 0x6f,
			0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48,
			0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,
			0x00, 0x04, 0x20, 0x93, 0x8d, 0xe7, 0x03, 0x69, 0x50, 0xe4, 0xe8, 0xbf, 0xb7, 0xc8, 0x34, 0x8e,
			0x26, 0x09, 0x7f, 0x1d, 0x0f, 0xa8, 0x36, 0xe9, 0x31, 0x5b, 0xa2, 0x26, 0xbf, 0xaf, 0x3c, 0x77,
			0x3b, 0xdb, 0x1c, 0xcf, 0x79, 0xee, 0x97, 0xe1, 0x2c, 0xf6, 0xb3, 0x30, 0x14, 0x53, 0x01, 0x7d,
			0xf6, 0xf6, 0x24, 0xd9, 0xb2, 0x8e, 0x41, 0x79, 0x08, 0x6e, 0xa9, 0xae, 0xd8, 0x15, 0xdd, 0x60,
			0xac, 0xc6, 0xa3, 0x82, 0x02, 0x54, 0x30, 0x82, 0x02, 0x50, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d,
			0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d,
			0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30,
			0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06,
			0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x3d, 0x7b, 0xd5, 0xa8, 0x51, 0xe3, 0x5e, 0x99,
			0xeb, 0xf5, 0x89, 0x39, 0x58, 0x60, 0xc2, 0x99, 0x00, 0x86, 0xc8, 0x72, 0x30, 0x1f, 0x06, 0x03,
			0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xde, 0x1b, 0x1e, 0xed, 0x79, 0x15, 0xd4,
			0x3e, 0x37, 0x24, 0xc3, 0x21, 0xbb, 0xec, 0x34, 0x39, 0x6d, 0x42, 0xb2, 0x30, 0x30, 0x58, 0x06,
			0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x4c, 0x30, 0x4a, 0x30, 0x21, 0x06,
			0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a,
			0x2f, 0x2f, 0x6f, 0x2e, 0x70, 0x6b, 0x69, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x2f, 0x77, 0x72, 0x32,
			0x30, 0x25, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x19, 0x68, 0x74,
			0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x2e, 0x70, 0x6b, 0x69, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x2f,
			0x77, 0x72, 0x32, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x2c, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x25,
			0x30, 0x23, 0x82, 0x0f, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
			0x63, 0x6f, 0x6d, 0x82, 0x10, 0x69, 0x6e, 0x62, 0x6f, 0x78, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
			0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x0c, 0x30, 0x0a,
			0x30, 0x08, 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x36, 0x06, 0x03, 0x55, 0x1d,
			0x1f, 0x04, 0x2f, 0x30, 0x2d, 0x30, 0x2b, 0xa0, 0x29, 0xa0, 0x27, 0x86, 0x25, 0x68, 0x74, 0x74,
			0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x2e, 0x70, 0x6b, 0x69, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x2f, 0x77,
			0x72, 0x32, 0x2f, 0x6f, 0x42, 0x46, 0x59, 0x59, 0x61, 0x68, 0x7a, 0x67, 0x56, 0x49, 0x2e, 0x63,
			0x72, 0x6c, 0x30, 0x82, 0x01, 0x04, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xd6, 0x79, 0x02,
			0x04, 0x02, 0x04, 0x81, 0xf5, 0x04, 0x81, 0xf2, 0x00, 0xf0, 0x00, 0x77, 0x00, 0x12, 0xf1, 0x4e,
			0x34, 0xbd, 0x53, 0x72, 0x4c, 0x84, 0x06, 0x19, 0xc3, 0x8f, 0x3f, 0x7a, 0x13, 0xf8, 0xe7, 0xb5,
			0x62, 0x87, 0x88, 0x9c, 0x6d, 0x30, 0x05, 0x84, 0xeb, 0xe5, 0x86, 0x26, 0x3a, 0x00, 0x00, 0x01,
			0x98, 0xe0, 0x9b, 0x01, 0xc5, 0x00, 0x00, 0x04, 0x03, 0x00, 0x48, 0x30, 0x46, 0x02, 0x21, 0x00,
			0x9d, 0x45, 0x1d, 0x9c, 0xec, 0x23, 0xc0, 0x2a, 0x12, 0xaf, 0xac, 0x2a, 0x9f, 0xfc, 0xf5, 0xde,
			0xd8, 0x3a, 0x17, 0xc9, 0x22, 0xf6, 0xf5, 0xad, 0x9d, 0xf7, 0x13, 0x0d, 0x49, 0x3e, 0x99, 0xde,
			0x02, 0x21, 0x00, 0x87, 0x8c, 0x5c, 0xbe, 0x0d, 0x7e, 0x8d, 0xc1, 0xee, 0x7d, 0xfe, 0xe8, 0x34,
			0xb3, 0x60, 0x54, 0xb1, 0xc4, 0xb9, 0xcd, 0x0f, 0xfe, 0x6d, 0xae, 0xe1, 0x27, 0x0a, 0xdb, 0xee,
			0x5d, 0x72, 0x81, 0x00, 0x75, 0x00, 0xaf, 0x18, 0x1a, 0x28, 0xd6, 0x8c, 0xa3, 0xe0, 0xa9, 0x8a,
			0x4c, 0x9c, 0x67, 0xab, 0x09, 0xf8, 0xbb, 0xbc, 0x22, 0xba, 0xae, 0xbc, 0xb1, 0x38, 0xa3, 0xa1,
			0x9d, 0xd3, 0xf9, 0xb6, 0x03, 0x0d, 0x00, 0x00, 0x01, 0x98, 0xe0, 0x9b, 0x06, 0xa3, 0x00, 0x00,
			0x04, 0x03, 0x00, 0x46, 0x30, 0x44, 0x02, 0x20, 0x24, 0x21, 0xed, 0x33, 0x4e, 0x12, 0x6b, 0xea,
			0xe3, 0xf2, 0x41, 0xe0, 0x06, 0x80, 0xcf, 0xdf, 0xb3, 0xd6, 0x90, 0x5b, 0xed, 0x7f, 0x1c, 0x2c,
			0xf1, 0x4f, 0xb9, 0xf8, 0xb5, 0x00, 0x2f, 0xd9, 0x02, 0x20, 0x36, 0x18, 0x0d, 0xef, 0xce, 0x95,
			0x8d, 0xdf, 0x35, 0x9e, 0xbb, 0x90, 0xfa, 0xab, 0x3c, 0x4c, 0xab, 0xcb, 0x32, 0x9e, 0x1e, 0x34,
			0x99, 0x8e, 0xa5, 0x8a, 0x53, 0x54, 0xd7, 0xc5, 0x59, 0xef, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
			0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x76, 0x85,
			0x89, 0x81, 0xe4, 0x9d, 0x3a, 0x0e, 0x4c, 0xe7, 0x10, 0x65, 0x6e, 0x05, 0x4c, 0xa0, 0x0d, 0xd8,
			0x70, 0x5d, 0xaf, 0xe9, 0xd7, 0x66, 0x05, 0x66, 0x5a, 0xd8, 0x5e, 0x45, 0x54, 0x19, 0xaa, 0x88,
			0x10, 0xdc, 0xb9, 0xf5, 0x8c, 0xea, 0x94, 0xfc, 0x7e, 0xdd, 0x91, 0xdc, 0xe2, 0xe3, 0x1b, 0x22,
			0x10, 0xd9, 0x31, 0x76, 0xea, 0xf9, 0x56, 0x7c, 0x54, 0x3b, 0xc7, 0x7c, 0x37, 0x09, 0xf3, 0xc4,
			0x85, 0xe5, 0x11, 0x0b, 0x7a, 0xfa, 0xd6, 0x1a, 0x05, 0x54, 0xd0, 0xd7, 0x9e, 0x7f, 0x5b, 0x26,
			0x3e, 0x40, 0x99, 0x8a, 0x52, 0x7c, 0x29, 0x62, 0xf9, 0x07, 0xa3, 0xa9, 0x61, 0x95, 0xde, 0xeb,
			0x7c, 0x12, 0x1e, 0xb8, 0xbf, 0x73, 0x20, 0xec, 0x64, 0xf0, 0x12, 0xab, 0xf8, 0x84, 0xe2, 0x38,
			0x97, 0x70, 0x5f, 0x25, 0xb8, 0x95, 0x1a, 0x1c, 0x47, 0xee, 0xbe, 0x96, 0x6b, 0xdc, 0x1f, 0x0c,
			0xa9, 0x96, 0x1f, 0xa0, 0x0f, 0x40, 0x74, 0x9c, 0x39, 0xa6, 0x11, 0xac, 0x57, 0x38, 0x25, 0xaa,
			0xb1, 0x7b, 0x34, 0x5d, 0xc6, 0xf5, 0x94, 0xb8, 0xb9, 0x2f, 0xa5, 0xd2, 0x97, 0x58, 0xbd, 0x0a,
			0x6d, 0xd7, 0x77, 0x42, 0xcb, 0x61, 0x96, 0xd6, 0x53, 0x10, 0xba, 0xda, 0xfa, 0x7a, 0x12, 0x1d,
			0xef, 0x1b, 0x4b, 0xdc, 0x64, 0xda, 0x1e, 0x78, 0x79, 0x16, 0x55, 0x04, 0xb0, 0xb9, 0x3f, 0x98,
			0x50, 0xa3, 0xef, 0xa3, 0x75, 0xf0, 0x44, 0xe5, 0x02, 0xc4, 0xd8, 0x47, 0x2c, 0x86, 0x66, 0x77,
			0xaf, 0x99, 0x6e, 0xca, 0xe1, 0x4b, 0x79, 0x1d, 0xbe, 0xf3, 0xc1, 0xeb, 0x08, 0x2b, 0x95, 0x60,
			0x9c, 0x02, 0xdc, 0x64, 0xde, 0xff, 0x89, 0x42, 0xd1, 0xa3, 0x95, 0x34, 0xbf, 0x37, 0x4e, 0x67,
			0xe1, 0x59, 0x02, 0xf0, 0x1b, 0x45, 0x12, 0x02, 0x81, 0x1c, 0xa6, 0xe8, 0x93, 0x69,
		};

		// Subject: C=US, O=Google Trust Services LLC, CN=GTS Root R1
		public static byte [] gts_root_r1 = {
			0x30, 0x82, 0x05, 0x57, 0x30, 0x82, 0x03, 0x3f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0d, 0x02,
			0x03, 0xe5, 0x93, 0x6f, 0x31, 0xb0, 0x13, 0x49, 0x88, 0x6b, 0xa2, 0x17, 0x30, 0x0d, 0x06, 0x09,
			0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00, 0x30, 0x47, 0x31, 0x0b, 0x30,
			0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03,
			0x55, 0x04, 0x0a, 0x13, 0x19, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73,
			0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x4c, 0x4c, 0x43, 0x31, 0x14,
			0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b, 0x47, 0x54, 0x53, 0x20, 0x52, 0x6f, 0x6f,
			0x74, 0x20, 0x52, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x36, 0x32, 0x32, 0x30, 0x30,
			0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x36, 0x32, 0x32, 0x30, 0x30, 0x30,
			0x30, 0x30, 0x30, 0x5a, 0x30, 0x47, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
			0x02, 0x55, 0x53, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x19, 0x47, 0x6f,
			0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69,
			0x63, 0x65, 0x73, 0x20, 0x4c, 0x4c, 0x43, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03,
			0x13, 0x0b, 0x47, 0x54, 0x53, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x52, 0x31, 0x30, 0x82, 0x02,
			0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
			0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xb6, 0x11,
			0x02, 0x8b, 0x1e, 0xe3, 0xa1, 0x77, 0x9b, 0x3b, 0xdc, 0xbf, 0x94, 0x3e, 0xb7, 0x95, 0xa7, 0x40,
			0x3c, 0xa1, 0xfd, 0x82, 0xf9, 0x7d, 0x32, 0x06, 0x82, 0x71, 0xf6, 0xf6, 0x8c, 0x7f, 0xfb, 0xe8,
			0xdb, 0xbc, 0x6a, 0x2e, 0x97, 0x97, 0xa3, 0x8c, 0x4b, 0xf9, 0x2b, 0xf6, 0xb1, 0xf9, 0xce, 0x84,
			0x1d, 0xb1, 0xf9, 0xc5, 0x97, 0xde, 0xef, 0xb9, 0xf2, 0xa3, 0xe9, 0xbc, 0x12, 0x89, 0x5e, 0xa7,
			0xaa, 0x52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29, 0xb3, 0x25, 0x2a, 0xb4, 0x48, 0xf9, 0x72, 0xe1, 0xca,
			0x64, 0xf7, 0xe6, 0x82, 0x10, 0x8d, 0xe8, 0x9d, 0xc2, 0x8a, 0x88, 0xfa, 0x38, 0x66, 0x8a, 0xfc,
			0x63, 0xf9, 0x01, 0xf9, 0x78, 0xfd, 0x7b, 0x5c, 0x77, 0xfa, 0x76, 0x87, 0xfa, 0xec, 0xdf, 0xb1,
			0x0e, 0x79, 0x95, 0x57, 0xb4, 0xbd, 0x26, 0xef, 0xd6, 0x01, 0xd1, 0xeb, 0x16, 0x0a, 0xbb, 0x8e,
			0x0b, 0xb5, 0xc5, 0xc5, 0x8a, 0x55, 0xab, 0xd3, 0xac, 0xea, 0x91, 0x4b, 0x29, 0xcc, 0x19, 0xa4,
			0x32, 0x25, 0x4e, 0x2a, 0xf1, 0x65, 0x44, 0xd0, 0x02, 0xce, 0xaa, 0xce, 0x49, 0xb4, 0xea, 0x9f,
			0x7c, 0x83, 0xb0, 0x40, 0x7b, 0xe7, 0x43, 0xab, 0xa7, 0x6c, 0xa3, 0x8f, 0x7d, 0x89, 0x81, 0xfa,
			0x4c, 0xa5, 0xff, 0xd5, 0x8e, 0xc3, 0xce, 0x4b, 0xe0, 0xb5, 0xd8, 0xb3, 0x8e, 0x45, 0xcf, 0x76,
			0xc0, 0xed, 0x40, 0x2b, 0xfd, 0x53, 0x0f, 0xb0, 0xa7, 0xd5, 0x3b, 0x0d, 0xb1, 0x8a, 0xa2, 0x03,
			0xde, 0x31, 0xad, 0xcc, 0x77, 0xea, 0x6f, 0x7b, 0x3e, 0xd6, 0xdf, 0x91, 0x22, 0x12, 0xe6, 0xbe,
			0xfa, 0xd8, 0x32, 0xfc, 0x10, 0x63, 0x14, 0x51, 0x72, 0xde, 0x5d, 0xd6, 0x16, 0x93, 0xbd, 0x29,
			0x68, 0x33, 0xef, 0x3a, 0x66, 0xec, 0x07, 0x8a, 0x26, 0xdf, 0x13, 0xd7, 0x57, 0x65, 0x78, 0x27,
			0xde, 0x5e, 0x49, 0x14, 0x00, 0xa2, 0x00, 0x7f, 0x9a, 0xa8, 0x21, 0xb6, 0xa9, 0xb1, 0x95, 0xb0,
			0xa5, 0xb9, 0x0d, 0x16, 0x11, 0xda, 0xc7, 0x6c, 0x48, 0x3c, 0x40, 0xe0, 0x7e, 0x0d, 0x5a, 0xcd,
			0x56, 0x3c, 0xd1, 0x97, 0x05, 0xb9, 0xcb, 0x4b, 0xed, 0x39, 0x4b, 0x9c, 0xc4, 0x3f, 0xd2, 0x55,
			0x13, 0x6e, 0x24, 0xb0, 0xd6, 0x71, 0xfa, 0xf4, 0xc1, 0xba, 0xcc, 0xed, 0x1b, 0xf5, 0xfe, 0x81,
			0x41, 0xd8, 0x00, 0x98, 0x3d, 0x3a, 0xc8, 0xae, 0x7a, 0x98, 0x37, 0x18, 0x05, 0x95, 0x02, 0x03,
			0x01, 0x00, 0x01, 0xa3, 0x42, 0x30, 0x40, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01,
			0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01,
			0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04,
			0x16, 0x04, 0x14, 0xe4, 0xaf, 0x2b, 0x26, 0x71, 0x1a, 0x2b, 0x48, 0x27, 0x85, 0x2f, 0x52, 0x66,
			0x2c, 0xef, 0xf0, 0x89, 0x13, 0x71, 0x3e, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
			0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x9f, 0xaa, 0x42, 0x26, 0xdb,
			0x0b, 0x9b, 0xbe, 0xff, 0x1e, 0x96, 0x92, 0x2e, 0x3e, 0xa2, 0x65, 0x4a, 0x6a, 0x98, 0xba, 0x22,
			0xcb, 0x7d, 0xc1, 0x3a, 0xd8, 0x82, 0x0a, 0x06, 0xc6, 0xf6, 0xa5, 0xde, 0xc0, 0x4e, 0x87, 0x66,
			0x79, 0xa1, 0xf9, 0xa6, 0x58, 0x9c, 0xaa, 0xf9, 0xb5, 0xe6, 0x60, 0xe7, 0xe0, 0xe8, 0xb1, 0x1e,
			0x42, 0x41, 0x33, 0x0b, 0x37, 0x3d, 0xce, 0x89, 0x70, 0x15, 0xca, 0xb5, 0x24, 0xa8, 0xcf, 0x6b,
			0xb5, 0xd2, 0x40, 0x21, 0x98, 0xcf, 0x22, 0x34, 0xcf, 0x3b, 0xc5, 0x22, 0x84, 0xe0, 0xc5, 0x0e,
			0x8a, 0x7c, 0x5d, 0x88, 0xe4, 0x35, 0x24, 0xce, 0x9b, 0x3e, 0x1a, 0x54, 0x1e, 0x6e, 0xdb, 0xb2,
			0x87, 0xa7, 0xfc, 0xf3, 0xfa, 0x81, 0x55, 0x14, 0x62, 0x0a, 0x59, 0xa9, 0x22, 0x05, 0x31, 0x3e,
			0x82, 0xd6, 0xee, 0xdb, 0x57, 0x34, 0xbc, 0x33, 0x95, 0xd3, 0x17, 0x1b, 0xe8, 0x27, 0xa2, 0x8b,
			0x7b, 0x4e, 0x26, 0x1a, 0x7a, 0x5a, 0x64, 0xb6, 0xd1, 0xac, 0x37, 0xf1, 0xfd, 0xa0, 0xf3, 0x38,
			0xec, 0x72, 0xf0, 0x11, 0x75, 0x9d, 0xcb, 0x34, 0x52, 0x8d, 0xe6, 0x76, 0x6b, 0x17, 0xc6, 0xdf,
			0x86, 0xab, 0x27, 0x8e, 0x49, 0x2b, 0x75, 0x66, 0x81, 0x10, 0x21, 0xa6, 0xea, 0x3e, 0xf4, 0xae,
			0x25, 0xff, 0x7c, 0x15, 0xde, 0xce, 0x8c, 0x25, 0x3f, 0xca, 0x62, 0x70, 0x0a, 0xf7, 0x2f, 0x09,
			0x66, 0x07, 0xc8, 0x3f, 0x1c, 0xfc, 0xf0, 0xdb, 0x45, 0x30, 0xdf, 0x62, 0x88, 0xc1, 0xb5, 0x0f,
			0x9d, 0xc3, 0x9f, 0x4a, 0xde, 0x59, 0x59, 0x47, 0xc5, 0x87, 0x22, 0x36, 0xe6, 0x82, 0xa7, 0xed,
			0x0a, 0xb9, 0xe2, 0x07, 0xa0, 0x8d, 0x7b, 0x7a, 0x4a, 0x3c, 0x71, 0xd2, 0xe2, 0x03, 0xa1, 0x1f,
			0x32, 0x07, 0xdd, 0x1b, 0xe4, 0x42, 0xce, 0x0c, 0x00, 0x45, 0x61, 0x80, 0xb5, 0x0b, 0x20, 0x59,
			0x29, 0x78, 0xbd, 0xf9, 0x55, 0xcb, 0x63, 0xc5, 0x3c, 0x4c, 0xf4, 0xb6, 0xff, 0xdb, 0x6a, 0x5f,
			0x31, 0x6b, 0x99, 0x9e, 0x2c, 0xc1, 0x6b, 0x50, 0xa4, 0xd7, 0xe6, 0x18, 0x14, 0xbd, 0x85, 0x3f,
			0x67, 0xab, 0x46, 0x9f, 0xa0, 0xff, 0x42, 0xa7, 0x3a, 0x7f, 0x5c, 0xcb, 0x5d, 0xb0, 0x70, 0x1d,
			0x2b, 0x34, 0xf5, 0xd4, 0x76, 0x09, 0x0c, 0xeb, 0x78, 0x4c, 0x59, 0x05, 0xf3, 0x33, 0x42, 0xc3,
			0x61, 0x15, 0x10, 0x1b, 0x77, 0x4d, 0xce, 0x22, 0x8c, 0xd4, 0x85, 0xf2, 0x45, 0x7d, 0xb7, 0x53,
			0xea, 0xef, 0x40, 0x5a, 0x94, 0x0a, 0x5c, 0x20, 0x5f, 0x4e, 0x40, 0x5d, 0x62, 0x22, 0x76, 0xdf,
			0xff, 0xce, 0x61, 0xbd, 0x8c, 0x23, 0x78, 0xd2, 0x37, 0x02, 0xe0, 0x8e, 0xde, 0xd1, 0x11, 0x37,
			0x89, 0xf6, 0xbf, 0xed, 0x49, 0x07, 0x62, 0xae, 0x92, 0xec, 0x40, 0x1a, 0xaf, 0x14, 0x09, 0xd9,
			0xd0, 0x4e, 0xb2, 0xa2, 0xf7, 0xbe, 0xee, 0xee, 0xd8, 0xff, 0xdc, 0x1a, 0x2d, 0xde, 0xb8, 0x36,
			0x71, 0xe2, 0xfc, 0x79, 0xb7, 0x94, 0x25, 0xd1, 0x48, 0x73, 0x5b, 0xa1, 0x35, 0xe7, 0xb3, 0x99,
			0x67, 0x75, 0xc1, 0x19, 0x3a, 0x2b, 0x47, 0x4e, 0xd3, 0x42, 0x8e, 0xfd, 0x31, 0xc8, 0x16, 0x66,
			0xda, 0xd2, 0x0c, 0x3c, 0xdb, 0xb3, 0x8e, 0xc9, 0xa1, 0x0d, 0x80, 0x0f, 0x7b, 0x16, 0x77, 0x14,
			0xbf, 0xff, 0xdb, 0x09, 0x94, 0xb2, 0x93, 0xbc, 0x20, 0x58, 0x15, 0xe9, 0xdb, 0x71, 0x43, 0xf3,
			0xde, 0x10, 0xc3, 0x00, 0xdc, 0xa8, 0x2a, 0x95, 0xb6, 0xc2, 0xd6, 0x3f, 0x90, 0x6b, 0x76, 0xdb,
			0x6c, 0xfe, 0x8c, 0xbc, 0xf2, 0x70, 0x35, 0x0c, 0xdc, 0x99, 0x19, 0x35, 0xdc, 0xd7, 0xc8, 0x46,
			0x63, 0xd5, 0x36, 0x71, 0xae, 0x57, 0xfb, 0xb7, 0x82, 0x6d, 0xdc,
		};

		// Subject: C=US, O=Google Trust Services, CN=WR2
		public static byte [] gts_ca_1c3 = {
			0x30, 0x82, 0x05, 0x0b, 0x30, 0x82, 0x02, 0xf3, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x7f,
			0xf0, 0x05, 0xa0, 0x7c, 0x4c, 0xde, 0xd1, 0x00, 0xad, 0x9d, 0x66, 0xa5, 0x10, 0x7b, 0x98, 0x30,
			0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x47,
			0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x22, 0x30,
			0x20, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x19, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54,
			0x72, 0x75, 0x73, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x4c, 0x4c,
			0x43, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b, 0x47, 0x54, 0x53, 0x20,
			0x52, 0x6f, 0x6f, 0x74, 0x20, 0x52, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32, 0x31,
			0x33, 0x30, 0x39, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x32, 0x30,
			0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
			0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
			0x15, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x53, 0x65,
			0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
			0x03, 0x57, 0x52, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
			0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,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, 0xcd, 0xcc, 0x7a, 0x14, 0xe4, 0x71, 0x03, 0xcb, 0x4d, 0x61, 0x2e, 0x61, 0x57,
			0xc5, 0x19, 0xa9, 0x0b, 0x98, 0x84, 0x1a, 0xe8, 0x79, 0x29, 0xd9, 0xb2, 0x8d, 0x2f, 0xff, 0x57,
			0x6a, 0x66, 0xe0, 0xce, 0xab, 0x95, 0xa8, 0x29, 0x96, 0x63, 0x70, 0x12, 0x67, 0x1e, 0x3a, 0xe1,
			0xdb, 0xb0, 0x21, 0x71, 0xd7, 0x7c, 0x9e, 0xfd, 0xaa, 0x17, 0x6e, 0xfe, 0x2b, 0xfb, 0x38, 0x17,
			0x14, 0xd1, 0x66, 0xa7, 0xaf, 0x9a, 0xb5, 0x70, 0xcc, 0xc8, 0x63, 0x81, 0x3a, 0x8c, 0xc0, 0x2a,
			0xa9, 0x76, 0x37, 0xce, 0xe3, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x81, 0xfe, 0x30, 0x81, 0xfb,
			0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86,
			0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01,
			0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30,
			0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff,
			0x02, 0x01, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xde, 0x1b,
			0x1e, 0xed, 0x79, 0x15, 0xd4, 0x3e, 0x37, 0x24, 0xc3, 0x21, 0xbb, 0xec, 0x34, 0x39, 0x6d, 0x42,
			0xb2, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xe4,
			0xaf, 0x2b, 0x26, 0x71, 0x1a, 0x2b, 0x48, 0x27, 0x85, 0x2f, 0x52, 0x66, 0x2c, 0xef, 0xf0, 0x89,
			0x13, 0x71, 0x3e, 0x30, 0x34, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04,
			0x28, 0x30, 0x26, 0x30, 0x24, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86,
			0x18, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x2e, 0x70, 0x6b, 0x69, 0x2e, 0x67, 0x6f,
			0x6f, 0x67, 0x2f, 0x72, 0x31, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x2b, 0x06, 0x03, 0x55, 0x1d, 0x1f,
			0x04, 0x24, 0x30, 0x22, 0x30, 0x20, 0xa0, 0x1e, 0xa0, 0x1c, 0x86, 0x1a, 0x68, 0x74, 0x74, 0x70,
			0x3a, 0x2f, 0x2f, 0x63, 0x2e, 0x70, 0x6b, 0x69, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x2f, 0x72, 0x2f,
			0x72, 0x31, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x0c, 0x30,
			0x0a, 0x30, 0x08, 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a,
			0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x45,
			0x75, 0x8b, 0xe5, 0x1f, 0x3b, 0x44, 0x13, 0x96, 0x1a, 0xab, 0x58, 0xf1, 0x35, 0xc9, 0x6f, 0x3d,
			0xd2, 0xd0, 0x33, 0x4a, 0x86, 0x33, 0xba, 0x57, 0x51, 0x4f, 0xee, 0xc4, 0x34, 0xda, 0x16, 0x12,
			0x4c, 0xbf, 0x13, 0x9f, 0x0d, 0xd4, 0x54, 0xe9, 0x48, 0x79, 0xc0, 0x30, 0x3c, 0x94, 0x25, 0xf2,
			0x1a, 0xf4, 0xba, 0x32, 0x94, 0xb6, 0x33, 0x72, 0x0b, 0x85, 0xee, 0x09, 0x11, 0x25, 0x34, 0x94,
			0xe1, 0x6f, 0x42, 0xdb, 0x82, 0x9b, 0x7b, 0x7f, 0x2a, 0x9a, 0xa9, 0xff, 0x7f, 0xa9, 0xd2, 0xde,
			0x4a, 0x20, 0xcb, 0xb3, 0xfb, 0x03, 0x03, 0xb8, 0xf8, 0x07, 0x05, 0xda, 0x59, 0x92, 0x2f, 0x18,
			0x46, 0x98, 0xce, 0xaf, 0x72, 0xbe, 0x24, 0x26, 0xb1, 0x1e, 0x00, 0x4d, 0xbd, 0x08, 0xad, 0x93,
			0x41, 0x44, 0x0a, 0xbb, 0xc7, 0xd5, 0x01, 0x85, 0xbf, 0x93, 0x57, 0xe3, 0xdf, 0x74, 0x12, 0x53,
			0x0e, 0x11, 0x25, 0xd3, 0x9b, 0xdc, 0xde, 0xcb, 0x27, 0x6e, 0xb3, 0xc2, 0xb9, 0x33, 0x62, 0x39,
			0xc2, 0xe0, 0x35, 0xe1, 0x5b, 0xa7, 0x09, 0x2e, 0x19, 0xcb, 0x91, 0x2a, 0x76, 0x5c, 0xf1, 0xdf,
			0xca, 0x23, 0x84, 0x40, 0xa5, 0x6f, 0xff, 0x9a, 0x41, 0xe0, 0xb5, 0xef, 0x32, 0xd1, 0x85, 0xae,
			0xaf, 0x25, 0x09, 0xf0, 0x62, 0xc5, 0x6e, 0xc2, 0xc8, 0x6e, 0x32, 0xfd, 0xb8, 0xda, 0xe2, 0xce,
			0x4a, 0x91, 0x4a, 0xf3, 0x85, 0x55, 0x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0xa1, 0xbf, 0xbc, 0x18, 0x3d,
			0x8b, 0x59, 0xf6, 0x8a, 0xc6, 0x05, 0x5e, 0x52, 0x18, 0xe2, 0x66, 0xe0, 0xda, 0xc1, 0xdc, 0xad,
			0x5a, 0x25, 0xaa, 0xf4, 0x45, 0xfc, 0xf1, 0x0b, 0x78, 0xa4, 0xaf, 0xb0, 0xf2, 0x73, 0xa4, 0x30,
			0xa8, 0x34, 0xc1, 0x53, 0x7f, 0x42, 0x96, 0xe5, 0x48, 0x41, 0xeb, 0x90, 0x46, 0x0c, 0x06, 0xdc,
			0xcb, 0x92, 0xc6, 0x5e, 0xf3, 0x44, 0x44, 0x43, 0x46, 0x29, 0x46, 0xa0, 0xa6, 0xfc, 0xb9, 0x8e,
			0x39, 0x27, 0x39, 0xb1, 0x5a, 0xe2, 0xb1, 0xad, 0xfc, 0x13, 0xff, 0x8e, 0xfc, 0x26, 0xe1, 0xd4,
			0xfe, 0x84, 0xf1, 0x50, 0x5a, 0x8e, 0x97, 0x6b, 0x2d, 0x2a, 0x79, 0xfb, 0x40, 0x64, 0xea, 0xf3,
			0x3d, 0xbd, 0x5b, 0xe1, 0xa0, 0x04, 0xb0, 0x97, 0x48, 0x1c, 0x42, 0xf5, 0xea, 0x5a, 0x1c, 0xcd,
			0x26, 0xc8, 0x51, 0xff, 0x14, 0x99, 0x67, 0x89, 0x72, 0x5f, 0x1d, 0xec, 0xad, 0x5a, 0xdd,
		};

		[DllImport (Constants.CoreFoundationLibrary)]
		extern static nint CFGetRetainCount (IntPtr handle);

		void CheckMailGoogleCom (SecCertificate cert, nint expectedRetainCount)
		{
			Assert.That (cert.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
			Assert.That (CFGetRetainCount (cert.Handle), Is.EqualTo (expectedRetainCount), "RetainCount");
			Assert.That (cert.SubjectSummary, Is.EqualTo ("mail.google.com"), "SubjectSummary");
			Assert.That ((nuint) (uint) mail_google_com.Length, Is.EqualTo (cert.DerData.Length), "DerData");
			if (TestRuntime.CheckXcodeVersion (8, 3)) {
				Assert.That (cert.GetCommonName (), Is.EqualTo ("mail.google.com"), "GetCommonName");
				Assert.That (cert.GetSerialNumber ().ToStableString (), Is.EqualTo ("<72cd64e0 1fb60945 1085a390 91b53128>"), "GetSerialNumber");

				var emailAddresses = cert.GetEmailAddresses ();
				Assert.IsTrue (emailAddresses is null || emailAddresses.Length == 0, "GetEmailAddresses");

				Assert.NotNull (cert.GetNormalizedIssuerSequence (), "GetNormalizedIssuerSequence");
				Assert.NotNull (cert.GetNormalizedSubjectSequence (), "GetNormalizedSubjectSequence");
#if !__MACCATALYST__
				Assert.NotNull (cert.GetPublicKey (), "GetPublicKey");
#endif
			}
			if (TestRuntime.CheckXcodeVersion (9, 0)) {
				NSError err;
				Assert.That (cert.GetSerialNumber (out err).ToStableString (), Is.EqualTo ("<72cd64e0 1fb60945 1085a390 91b53128>"), "GetSerialNumber/NSError");
				Assert.Null (err, "err");
			}
			if (TestRuntime.CheckXcodeVersion (10, 0)) {
				Assert.NotNull (cert.GetKey (), "GetKey");
			}
			if (TestRuntime.CheckXcodeVersion (16, 0)) {
				Assert.NotNull (cert.NotValidBeforeDate, "NotValidBeforeDate");
				Assert.NotNull (cert.NotValidAfterDate, "NotValidAfterDate");
			}
		}

		[Test]
		public void MailNSData ()
		{
			using (var data = NSData.FromArray (mail_google_com))
			using (var sc = new SecCertificate (data)) {
				CheckMailGoogleCom (sc, 1);
			}
		}

		[Test]
		public void MailRaw ()
		{
			using (var sc = new SecCertificate (mail_google_com)) {
				CheckMailGoogleCom (sc, 1);
			}
		}

		[Test]
		public void MailX1 ()
		{
			using (var cert = X509CertificateLoader.LoadCertificate (mail_google_com)) {
				/*
				 * This X509Certificate constructor will use SecCertificateCreateWithData() and
				 * store the SecCertificateRef in its Handle.
				 */
				Assert.That (cert.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
				Assert.That (CFGetRetainCount (cert.Handle), Is.EqualTo ((nint) 1), "RetainCount");
				using (var sc = new SecCertificate (cert)) {
					// dotnet PAL layer does not return the same instance
					CheckMailGoogleCom (sc, 1); // so the new one is RC == 1
					Assert.That (cert.ToString (true), Is.EqualTo (sc.ToX509Certificate ().ToString (true)), "X509Certificate");
				}
			}
		}

		[Test]
		[Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=39952")]
		public void MailX2 ()
		{
			using (var cert = X509CertificateLoader.LoadCertificate (mail_google_com)) {
				/*
				 * FIXME: This X509Certificate2 constructor will use Mono.Security to parse the
				 *        certificate, but also call the base class'es .ctor with the byte array.
				 */
				Assert.That (cert.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
				Assert.That (CFGetRetainCount (cert.Handle), Is.EqualTo (1), "RetainCount");
				using (var sc = new SecCertificate (cert)) {
					Assert.That (sc.Handle, Is.EqualTo (cert.Handle), "Same Handle");
					CheckMailGoogleCom (sc, 2);
					Assert.That (cert.ToString (), Is.EqualTo (sc.ToX509Certificate2 ().ToString ()), "X509Certificate2");
				}
			}
		}

		[Test]
		public void GenerateKeyPairTest ()
		{
			SecKey private_key;
			SecKey public_key;
			var att = new SecPublicPrivateKeyAttrs ();
			att.Label = $"{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";
			att.IsPermanent = false;
			att.ApplicationTag = new NSData ();
			att.EffectiveKeySize = 1024;
			att.CanEncrypt = false;
			att.CanDecrypt = false;
			att.CanDerive = false;
			att.CanSign = false;
			att.CanVerify = false;
			att.CanUnwrap = false;

			try {
				Assert.That (SecKey.GenerateKeyPair (SecKeyType.RSA, 1024, att, out public_key, out private_key), Is.EqualTo (SecStatusCode.Success), "GenerateKeyPair");


				Assert.Throws<ArgumentException> (() => { SecKey.GenerateKeyPair (SecKeyType.Invalid, -1, null, out _, out _); }, "GenerateKeyPair - Invalid");
				Assert.That (SecKey.GenerateKeyPair (SecKeyType.RSA, -1, null, out _, out _), Is.EqualTo (SecStatusCode.Param), "GenerateKeyPair - Param issue, invalid RSA key size");
				Assert.That (SecKey.GenerateKeyPair (SecKeyType.RSA, 1024, null, out _, out _), Is.EqualTo (SecStatusCode.Success), "GenerateKeyPair - Null optional params, success");

#if IOS
				var att2 = new SecPublicPrivateKeyAttrs ();
				att2.Label = att.Label;
				att2.IsPermanent = false;
				att2.EffectiveKeySize = 1024;
				att2.CanEncrypt = true;
				att2.CanDecrypt = true;
				att2.CanDerive = true;
				att2.CanSign = true;
				att2.CanVerify = true;
				att2.CanUnwrap = true;
				Assert.That (SecKey.GenerateKeyPair (SecKeyType.RSA, 1024, att, att2, out public_key, out private_key), Is.EqualTo (SecStatusCode.Success), "GenerateKeyPair - iOS Only API");
#endif
				if (TestRuntime.CheckXcodeVersion (8, 0)) {
					using (var attrs = public_key.GetAttributes ()) {
						Assert.That (attrs.Count, Is.GreaterThan ((nuint) 0), "public/GetAttributes");
					}
					using (var attrs = private_key.GetAttributes ()) {
						Assert.That (attrs.Count, Is.GreaterThan ((nuint) 0), "private/GetAttributes");
					}
				}
			} finally {
				KeyTest.DeleteKeysWithLabel (att.Label);
			}
		}

		[Test]
		public void X2 ()
		{
			TestRuntime.AssertXcodeVersion (10, 0);
			using (var x1 = new SecCertificate (mail_google_com))
			using (var x2 = new SecCertificate2 (x1)) {
				Assert.That (x2.Certificate.GetCommonName (), Is.EqualTo (x1.GetCommonName ()), "CommonName");
			}
		}
	}
}
